﻿$(document).ready(function () {
    $("img[etype='weibo-pic']").click(function () {
        var $img = $(this);
        var $container = $img.parent().parent();
        if ($img.attr("src") == $img.attr("thumbsrc")) {
            $img.attr("src", "");
            $img.attr("src", $img.attr("middlesrc"));
            //$container.removeClass("weibo-pic-thumb").addClass("weibo-pic-middle");
            $("<div class='weibo-pic-popup'></div>").
                html("<a href='" + $img.attr("originsrc") + "' target='_blank'>original</a>").
                prependTo($container);
        } else {
            $img.attr("src", $img.attr("thumbsrc"));
            $("div").remove(".weibo-pic-popup");
            //$container.removeClass("weibo-pic-middle").addClass("weibo-pic-thumb");
        }
        return false;
    });

    //    $("#remove-zombie").click(function () {
    //        $.post("/User/DoRemoveZombie");
    //        $(this).attr("disabled", "disabled");
    //    });
    $publisher = $("#status-area").addClass("status-area");
    $toolbar = $("#status-toolbar").hide();

    $publisher.focusin(function () {
        if ($publisher.html() == $publisher.attr("hints")) {
            $publisher.html("");
        }

        $publisher.animate({ height: "60px" },
            100, function () {
                $publisher.removeClass("status-area-unselected").addClass("status-area-selected");
                $toolbar.show();
            });
    });

    //    $publisher.focusout(function () {
    //     //   console.log($publisher.html());
    //        if ($publisher.html() == "" || $publisher.html() == "<br>") {
    //            $publisher.animate({ height: "22px" },
    //            100, function () {
    //                $publisher.removeClass("status-area-selected").addClass("status-area-unselected"); ;
    //                $publisher.html($publisher.attr("hints"));
    //                $toolbar.hide();
    //            });
    //        }
    //    });

    $("#status-share").click(function () {
        $("#status-hidden").val($publisher.val());
        setTimeout(function () {
            $("#status-share").attr("disabled", "true")
        }, 10);
    });

    $("#status-close").click(function () {
         $publisher.animate({ height: "22px" },
            100, function () {
                $publisher.removeClass("status-area-selected").addClass("status-area-unselected"); ;
                $publisher.html($publisher.attr("hints"));
                $toolbar.hide();
            });
    });

    $("#status-choose-file").click(function () {
        
    });

    var WB = {};

    WB = {
        checkUnread: function () {
            $.getJSON("/Service/Unread", null, function (unread) {
                $("#atme-count-wrapper").toggle(unread.mentions > 0);
                $("#atme-count").html(unread.mentions);
                $("#fans-count-wrapper").toggle(unread.followers > 0);
                $("#fans-count").html(unread.followers);
                $("#comments-count-wrapper").toggle(unread.comments > 0);
                $("#comments-count").html(unread.comments);
            });
            setTimeout(WB.checkUnread, 10000);
        }
    };

    WB.checkUnread();
});

function onListBegin() {
    $("#list").html("loading...").scrollTop();
}

function onListSuccess() {

}

function onListFailure() {
    alert("list failed!");
}